//
//  TabBarController.m
//  EducationLive
//
//  Created by Apple on 2017/10/17.
//  Copyright © 2017年 ZhouHao. All rights reserved.
//

#import "TabBarController.h"
#import "UIImage+Color.h"
#import "UITabBarController+AddChildVC.h"
#import "HomeVC.h"
#import "CourseVC.h"
#import "MeVC.h"
#import "NavigationController.h"

@interface TabBarController ()

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureTabBar];
    
    [self configureChildViewControllers];
}

- (void)configureTabBar
{
//    self.tabBar.shadowImage = [UIImage imageNamed:@"tabbartop-line"];
//    if (kIsIOS8Later) {
//        [self.tabBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:238/255.0 green:240/255.0 blue:245/255.0 alpha:0.78]]];
//        // blur效果
//        UIVisualEffectView *visualEfView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
//        visualEfView.frame = CGRectMake(0, -1, CGRectGetWidth(self.tabBar.frame), CGRectGetHeight(self.tabBar.frame)+1);
//        visualEfView.alpha = 1.0;
//        [self.tabBar insertSubview:visualEfView atIndex:0];
//    }
    
    [[UITabBarItem appearanceWhenContainedIn:[TabBarController class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName :[UIColor colorWithRed:113/255.0 green:113/255.0 blue:113/255.0 alpha:1.0] } forState:UIControlStateNormal];
    
    [[UITabBarItem appearanceWhenContainedIn:[TabBarController class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName :GreenColor } forState:UIControlStateSelected];
}

- (void)configureChildViewControllers
{
    // 首页
    [self addHomeController];
    
    // 课程
    [self addCourseController];
    
    // 我
    [self addMeController];
}

- (void)addHomeController
{
    UIEdgeInsets imageInsets = UIEdgeInsetsZero;
    UIOffset titlePosition = UIOffsetMake(0, -2);
    
    HomeVC *homeVC = [[HomeVC alloc]init];
    
    [self addChildViewController:homeVC title:@"首页" image:@"tab_home_default" selectedImage:@"tab_home_selected" imageInsets:imageInsets titlePosition:titlePosition navControllerClass:[NavigationController class]];
}

- (void)addCourseController
{
    UIEdgeInsets imageInsets = UIEdgeInsetsZero;
    UIOffset titlePosition = UIOffsetMake(0, -2);
    
    CourseVC *courseVC = [[CourseVC alloc]init];
    
    [self addChildViewController:courseVC title:@"课程" image:@"tab_course_default" selectedImage:@"tab_course_selected" imageInsets:imageInsets titlePosition:titlePosition navControllerClass:[NavigationController class]];
}

- (void)addMeController
{
    UIEdgeInsets imageInsets = UIEdgeInsetsZero;
    UIOffset titlePosition = UIOffsetMake(0, -2);
    
    MeVC *meVC = [[MeVC alloc]init];
    
    [self addChildViewController:meVC title:@"我" image:@"tab_me_default" selectedImage:@"tab_me_selected" imageInsets:imageInsets titlePosition:titlePosition navControllerClass:[NavigationController class]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
